package com.echoesnet.echoesshortvideo.views.adapters;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.echoesnet.echoesshortvideo.Persistence.BlackListBean;
import com.echoesnet.echoesshortvideo.Persistence.TinyVideoInfoEntity;
import com.echoesnet.echoesshortvideo.R;
import com.echoesnet.echoesshortvideo.Utils.CommonUtils;
import com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder;
import com.marshalchen.ultimaterecyclerview.UltimateViewAdapter;

import java.util.List;


/**
 * Copyright (C) 2017 在线回声（天津）科技发展有限公司
 * 在线回声完全享有此软件的著作权，违者必究
 *
 * @author Administrator
 * @version 1.0
 * @modifier
 * @createDate 2018/4/24
 * @description
 */
public class BlackListAdapter extends UltimateViewAdapter<UltimateRecyclerviewViewHolder>
{
    private Activity mAct;
    private List<BlackListBean> mList;

    private int itemW, itemH;
    public  BlackListAdapter(Activity mAct ,List<BlackListBean> mList)
    {
        this.mAct = mAct;
        this.mList = mList;
//        itemW = CommonUtils.getScreenWidth(mAct);
//        //<!-- 374px * 480 px -->
//        //<!-- 高是宽的1.28倍 -->
//        itemH = (int)(itemW * 0.3);
    }


    @Override
    public void onBindViewHolder(@NonNull UltimateRecyclerviewViewHolder holder, int position)
    {
        bindDefaultTileItem(position, holder);
    }

    private void bindDefaultTileItem(int position, UltimateRecyclerviewViewHolder holder)
    {

        BlackListBean bean = mList.get(position);

        TextView tvNickname = holder.getView().findViewById(R.id.tv_nickname);
        TextView tvRemove = holder.getView().findViewById(R.id.tv_remove);
        tvNickname.setTag(R.id.viewTagFirst,bean);
        tvRemove.setTag(R.id.viewTagSecond,bean);
        tvNickname.setText(bean.getName());
    }

    @Override
    public UltimateRecyclerviewViewHolder newFooterHolder(View view)
    {
        return null;
    }

    @Override
    public UltimateRecyclerviewViewHolder newHeaderHolder(View view)
    {
        return null;
    }

    @Override
    public UltimateRecyclerviewViewHolder onCreateViewHolder(ViewGroup parent)
    {
        View view = LayoutInflater.from(mAct).inflate(R.layout.black_item,null);

//        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(itemW,itemH);
//        view.setLayoutParams(new ViewGroup.LayoutParams(itemW,itemH));


        view.findViewById(R.id.tv_nickname).setOnClickListener(v -> {
            if (onItemClickListener != null)
            {
                onItemClickListener.onClick(v, (BlackListBean) v.getTag(R.id.viewTagFirst));
            }
        });


        view.findViewById(R.id.tv_remove).setOnClickListener(v -> {
            if (onItemClickListener != null)
            {
                onItemClickListener.onClick(v, (BlackListBean) v.getTag(R.id.viewTagSecond));
            }
        });

        return new UltimateRecyclerviewViewHolder(view);
    }



    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent)
    {
        return null;
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position)
    {

    }


    @Override
    public int getAdapterItemCount()
    {
        return mList.size();
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    private ItemClickListener onItemClickListener;

    public void setOnItemClickListener(ItemClickListener listener)
    {
        this.onItemClickListener = listener;
    }
    public interface ItemClickListener
    {
        void onClick(View v, BlackListBean tag);
    }
    @Override
    public long generateHeaderId(int position)
    {
        return 0;
    }


}
